package nl.haemers.geom
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	import nl.haemers.base.BaseSprite;
	import nl.haemers.interfaces.ICell;
	
	import nl.haemers.utils.Logger;
	/**
	 * @author Jonathan Haemers
	*/
	public class BaseCell extends BaseSprite implements ICell
	{
		protected var _backgroundColor				:uint;
		protected var _lineColor					:uint;
		protected var _index						:int;
		protected var _cellLocation					:Point;
		protected var _cellWidth					:Number;
		protected var _cellHeight					:Number;
		
		public function BaseCell() 
		{
			super();
		}
		
		/** Public methods **/
		public function draw() : void
		{
			checkRequirements();
			drawCell();
		}
		
		/** Getters & Setters **/
		public function get backgroundColor() : uint
		{ 
			return _backgroundColor;
		}
		public function set backgroundColor( value:uint ) : void 
		{
			_backgroundColor = value;
		}
		
		public function get lineColor() : uint
		{ 
			return _lineColor;
		}
		public function set lineColor( value:uint ) : void 
		{
			_lineColor = value;
		}
		
		public function get index() : int
		{ 
			return _index;
		}
		public function set index( value:int ) : void 
		{
			_index = value;
		}
		
		public function get cellLocation() : Point
		{ 
			return _cellLocation;
		}
		public function set cellLocation( value:Point ) : void 
		{
			_cellLocation = value;
		}
		
		public function get cellWidth() : Number
		{ 
			return _cellWidth;
		}
		public function set cellWidth(value:Number) : void
		{
			Logger.i(value.toString());
			if (value > 0)
			{
				_cellWidth = value;
			}
		}
		
		public function get cellHeight() : Number
		{ 
			return _cellHeight;
		}
		public function set cellHeight( value:Number ) : void 
		{
			if (value > 0)
			{
				_cellHeight = value;
			}
		}
		
		/** Protected methods **/
		override protected function init(e:Event = null) : void
		{
			super.init(e);
			startup();
		}
		
		protected function startup() : void
		{
			
		}
		
		protected function drawCell() : void
		{
			if (_lineColor)
			{
				graphics.lineStyle(1, _lineColor, 1);
			}
			if (_backgroundColor)
			{
				graphics.beginFill(_backgroundColor, 1);
			}
			graphics.drawRect(_cellWidth * -.5, _cellHeight * -.5, _cellWidth, _cellHeight);
			graphics.endFill();
		}
		
		protected function checkRequirements() : void
		{
			if (_cellWidth <= 0)
			{
				Logger.w("No cellWidth declared!", BaseCell);
			}
			if (_cellHeight <= 0)
			{
				Logger.w("No cellHeight declared!", BaseCell);
			}			
		}
		
	}

}